﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VOEISHubPushServiceClient
{
    class ServiceDatabase : IServiceDatabase
    {
        private string _ServiceSQLServer;
        private string _ServiceDatabase;
        private string _ServiceAuthentication;
        private string _ServiceUserName;
        private string _ServicePassword;
        private string _ServiceConnectionString;
        private string _ServiceMaxRecords;
        private string _ServiceDBTimeout;
        private string _ServiceLastRecordDateTime;

        public string ServiceSQLServer
        {
            get
            {
                return _ServiceSQLServer;
            }

            set
            {
                _ServiceSQLServer = value;                
            }
        }

        public string ServiceDatabase
        {
            get
            {
                return _ServiceDatabase;
            }

            set
            {
                _ServiceDatabase = value;
            }
        }

        public string ServiceAuthentication
        {
            get
            {
                return _ServiceAuthentication;
            }

            set
            {
                _ServiceAuthentication = value;
            }
        }

        public string ServiceUserName
        {
            get
            {
                return _ServiceUserName;
            }

            set
            {
                _ServiceUserName= value;
            }
        }

        public string ServicePassword
        {
            get
            {
                return "********";
            }
            set
            {
                _ServicePassword = value;
            }
        }

        public string ServiceConnectionString
        {
            get
            {
                if (_ServiceAuthentication == "Windows")
                {
                    return "Data Source=" + _ServiceSQLServer + ";Initial Catalog=" + _ServiceDatabase + ";Integrated Security=SSPI;";
                }
                else
                {
                    return "Data Source=" + _ServiceSQLServer + ";Initial Catalog=" + _ServiceDatabase + ";User Id=" + _ServiceUserName + ";Password=**********;";
                }
            }
        }

        public string ServiceMaxRecords
        {
            get
            {
                return _ServiceMaxRecords;
            }
            set
            {
                _ServiceMaxRecords = value;
            }
        }

        public string ServiceDBTimeout
        {
            get
            {
                return _ServiceDBTimeout;
            }

            set 
            {
                _ServiceDBTimeout = value;
            }
        }

        public string ServiceLastRecordDateTime
        {
            get
            {
                return _ServiceLastRecordDateTime;
            }

            set
            {
                _ServiceLastRecordDateTime = value;
            }
        }

        public ServiceDatabase(string _ServiceSQLServer, string ServiceDatabase)
        {
            _ServiceSQLServer = ServiceSQLServer;
            _ServiceDatabase = ServiceDatabase;
            _ServiceAuthentication = "Windows";
            SetServiceConnectionString();
        }

        public ServiceDatabase(string _ServiceSQLServer, string ServiceDatabase, string ServiceUserName, string ServicePassword)
        {
            _ServiceSQLServer = ServiceSQLServer;
            _ServiceDatabase = ServiceDatabase;
            _ServiceAuthentication = "SQL";
            _ServiceUserName = ServiceUserName;
            _ServicePassword = ServicePassword;
            SetServiceConnectionString();
        }        

        public void SetServiceConnectionString()
        {
            //TODO: I need to make sure that none of the fields are null
            if (_ServiceAuthentication == "Windows")
            {
                _ServiceConnectionString = "Data Source=" + _ServiceSQLServer + ";Initial Catalog=" + _ServiceDatabase + ";Integrated Security=SSPI;";
            }
            else
            {
                _ServiceConnectionString = "Data Source=" + _ServiceSQLServer + ";Initial Catalog=" + _ServiceDatabase + ";User Id=" + _ServiceUserName + ";Password=" + _ServicePassword + ";";
            }
        }
    }
}
